package com.sleepcamel.resteasyConfigurator.components.wizard.pages;

import org.eclipse.jface.dialogs.IPageChangedListener;
import org.eclipse.jface.dialogs.PageChangedEvent;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;

import com.sleepcamel.resteasyConfigurator.model.App;
import com.sleepcamel.resteasyConfigurator.model.dbwizard.SecondPageModel;

public class SecondPageView extends WizardPage implements IPageChangedListener {

	private SecondPageModel secondPage;

	public SecondPageView(SecondPageModel secondPage) {
		super("Done");
		this.secondPage = secondPage;
	}

	@Override
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);
		setControl(container);
		WizardDialog wizardDialog = (WizardDialog) getWizard().getContainer();
		wizardDialog.addPageChangedListener(this);
	}

	@Override
	public boolean isPageComplete() {
		return secondPage.isComplete();
	}

	@Override
	public void pageChanged(PageChangedEvent paramPageChangedEvent) {
		if ( paramPageChangedEvent.getSelectedPage().equals(this) ){
			try{
				App.getInstance().generateFilesFromDB();
				setMessage("Files were generated");
			}catch(Exception e){
				setMessage(e.toString());
			}
		}
	}
}
